﻿namespace IBTrader.Indicator.Average
{
    using IBTrader.Modules.Read;
    using IBTrader.Charts;
    
    class EMA : Base
    {
        private readonly double factor;
        internal Line Last { get; private set; }
        public EMA(Worker worker, double interval = 20) : base(worker) { factor = 2.0 / (1.0 + interval); }
        public override void Add(object _, Line line) 
        {
            var last = Last ?? line;                                    // get last
            var p = (line.Price - last.Price) * factor + last.Price;    // calc price
            Last = NewLine(line, p);                                    // store last
            OnHit(Last);
        }
    }
}